package store.dao;

import store.model.Category;
import store.model.Recover;

import java.sql.SQLException;
import java.util.List;

public class CategoryDao {

    private static DBUtils<Category> dbUtils;
    private static Recover<Category> categoryRecover;

    public CategoryDao() {
        dbUtils = new DBUtils<>();
        categoryRecover = new Category.CategoryRecover();
    }

    public List<Category> selectAll() throws SQLException, ClassNotFoundException {
        String sql = "select * from category";
        return dbUtils.executeQuery1(sql, categoryRecover);
    }

    public int insert(Category category) throws SQLException, ClassNotFoundException {
        String sql = "insert into category(name) values(?)";
        return dbUtils.executeUpdate(sql, category.getName());
    }
}
